//
//  LJFSortCollectionCell.m
//  SevenZhou
//
//  Created by qianfeng on 15/9/24.
//  Copyright (c) 2015年 ljf. All rights reserved.
//

#import "LJFSortCollectionCell.h"
#import "LJFScenicModel.h"
#import "LJFContinentModel.h"
#import "LJFCountryModel.h"
#import "LJFCityModel.h"
#import "LJFsortHeadView.h"

@implementation LJFSortCollectionCell

- (void)awakeFromNib
{
}

- (void)setCollectionRow:(NSInteger)collectionRow
{
    _collectionRow = collectionRow;
    
    [_mytableView reloadData];
}

#pragma mark -UITableViewDataSource,UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_collectionRow == 0)
    {
        return _dataArr.count;
        
    }else if(_collectionRow == 1)
    {
        LJFContinentModel *model = _dataArr[_index1];
        
        return model.children.count;
        
    }else
    {
        LJFContinentModel *model = _dataArr[_index1];
        
        LJFCountryModel *model1 = model.children[_index2];

        
        return model1.children.count;
    }
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reusedID=@"reusedID";
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reusedID];
    
    if (!cell)
    {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusedID];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    if (_collectionRow == 0)
    {
        LJFContinentModel *model = _dataArr[indexPath.row];
        
        cell.textLabel.text = model.name;
    }
    else if (_collectionRow == 1)
    {
        LJFContinentModel *model = _dataArr[_index1];
        
        LJFCountryModel *model1 = model.children[indexPath.row];
        
        cell.textLabel.text = model1.name;
        
    } else
    {
        LJFContinentModel *model = _dataArr[_index1];
        
        LJFCountryModel *model1 = model.children[_index2];
        
        LJFCityModel *model2 = model1.children[indexPath.row];
        
        cell.textLabel.text = model2.name;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_collectionRow == 0)
    {
         LJFContinentModel *model = _dataArr[indexPath.row];
        
        _name1 = model.name;
        
         self.index1 = indexPath.row;
        
        [_mydelegate SortCollectionCell:self didSelectWithindex1:_index1 andIndex2:_index2 andoffset:_collectionRow+1 andTitle1:_name1 andTitle2:_name2];
    }
    else if (_collectionRow == 1)
    {
        self.index2 = indexPath.row;
        
        LJFContinentModel *model = _dataArr[_index1];
        
        LJFCountryModel *model1 = model.children[indexPath.row];
        
        _name2 = model1.name;
        
        [_mydelegate SortCollectionCell:self didSelectWithindex1:_index1 andIndex2:_index2 andoffset:_collectionRow +1 andTitle1:_name1 andTitle2:_name2];
    }else
    {
        LJFContinentModel *model = _dataArr[_index1];
        
        LJFCountryModel *model1 = model.children[_index2];
        
        LJFCityModel *model2 = model1.children[indexPath.row];
        
        NSString *goodid = model2.Myid;
        
        [_mydelegate removehiddenView:goodid and:model2.name];

    }
}


@end
